/* Copyright (c) 2009 Google Inc.
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *     http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.jessies.blogbaboon;

import com.google.gdata.data.Link;
import com.google.gdata.data.blogger.BlogEntry;

/**
 * A simplified BlogEntry that's more convenient for our purposes.
 */
public class BlogInfo implements Comparable<BlogInfo> {
  private final String title;
  private final String summary;
  private final String id;
  private final String url;
  
  public BlogInfo(BlogEntry e) {
    this.title = e.getTitle().getPlainText();
    this.summary = e.getSummary().getPlainText();
    this.id = e.getId();
    this.url = e.getLink(Link.Rel.ALTERNATE, "text/html").getHref();
  }
  
  // Java 6: @Override
  public int compareTo(BlogInfo rhs) {
    return title.compareTo(rhs.title);
  }
  
  public String getId() {
    return id.split("blog-")[1];
  }
  
  public String getBlogUrl() {
    return url;
  }
  
  @Override public String toString() {
    String result = title;
    if (summary.length() > 0) {
      result += " (" + summary + ")";
    }
    return result;
  }
}
